package com.ruoyi.web.controller.module.examine;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.examine.ExamineApproveRegInfo;
import com.ruoyi.system.service.module.examine.IExamineApproveRegInfoService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 审批记录 采购 类型的明细Controller
 *
 * @author ruoyi
 * @date 2022-11-23
 */
@Validated
@Api(value = "审批记录 采购 类型的明细控制器", tags = {"审批记录 采购 类型的明细管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/approve/reg/info")
public class ExamineApproveRegInfoController extends BaseController {

    private final IExamineApproveRegInfoService examineApproveRegInfoService;

    /**
     * 查询审批记录 采购 类型的明细列表
     */
    @ApiOperation("查询审批记录 采购 类型的明细列表")
    @PreAuthorize("@ss.hasPermi('module:info:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamineApproveRegInfo> list(@Validated ExamineApproveRegInfo examineApproveRegInfo) {
        QueryWrapper<ExamineApproveRegInfo> qw = new QueryWrapper<>();

        TableDataInfo<ExamineApproveRegInfo> td = PageUtils.buildDataInfo(examineApproveRegInfoService.page(PageUtils.buildPage(),qw));
        List<ExamineApproveRegInfo> list = td.getRows();
        return td;
    }

    /**
     * 导出审批记录 采购 类型的明细列表
     */
    @ApiOperation("导出审批记录 采购 类型的明细列表")
    @PreAuthorize("@ss.hasPermi('module:info:export')")
    @Log(title = "审批记录 采购 类型的明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ExamineApproveRegInfo> export(@Validated ExamineApproveRegInfo examineApproveRegInfo) {
        List<ExamineApproveRegInfo> list = examineApproveRegInfoService.list();
        ExcelUtil<ExamineApproveRegInfo> util = new ExcelUtil<ExamineApproveRegInfo>(ExamineApproveRegInfo.class);
        return util.exportExcel(list, "审批记录 采购 类型的明细");
    }

    /**
     * 获取审批记录 采购 类型的明细详细信息
     */
    @ApiOperation("获取审批记录 采购 类型的明细详细信息")
    @PreAuthorize("@ss.hasPermi('module:info:query')")
    @GetMapping("/{id}")
    public List<ExamineApproveRegInfo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        QueryWrapper<ExamineApproveRegInfo> qw=new QueryWrapper<>();
        if (id!=null){
            qw.eq("approve_record_id",id);
        }
        TableDataInfo<ExamineApproveRegInfo> td = PageUtils.buildDataInfo(examineApproveRegInfoService.page(PageUtils.buildPage(),qw));
        List<ExamineApproveRegInfo> list = td.getRows();
        return list;
    }

    /**
     * 新增审批记录 采购 类型的明细
     */
    @ApiOperation("新增审批记录 采购 类型的明细")
    @PreAuthorize("@ss.hasPermi('module:info:add')")
    @Log(title = "审批记录 采购 类型的明细", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ExamineApproveRegInfo examineApproveRegInfo) {
        return toAjax(examineApproveRegInfoService.save(examineApproveRegInfo) ? 1 : 0);
    }

    /**
     * 修改审批记录 采购 类型的明细
     */
    @ApiOperation("修改审批记录 采购 类型的明细")
    @PreAuthorize("@ss.hasPermi('module:info:edit')")
    @Log(title = "审批记录 采购 类型的明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ExamineApproveRegInfo examineApproveRegInfo) {
        return toAjax(examineApproveRegInfoService.updateById(examineApproveRegInfo) ? 1 : 0);
    }

    /**
     * 删除审批记录 采购 类型的明细
     */
    @ApiOperation("删除审批记录 采购 类型的明细")
    @PreAuthorize("@ss.hasPermi('module:info:remove')")
    @Log(title = "审批记录 采购 类型的明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(examineApproveRegInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
